﻿package systems.traer 
{
	import adobe.utils.CustomActions;
	import flash.display.Graphics;
	import flash.geom.Vector3D;
	public class Particle
	{
		static private var idCount:int = 0;
		private var _id:int;
		protected var _position:Vector3D;
		protected var _velocity:Vector3D;
		protected var _force:Vector3D;
		protected var _mass:Number;
		protected var _age:Number;
		protected var _dead:Boolean;
		
		private var _fixed:Boolean; 
		private var _color:uint = 0xFF0000;
		
		public function Particle(_mass:Number) 
		{
			position = new Vector3D();
			velocity = new Vector3D();
			force = new Vector3D();
			mass = _mass;
			age = 0;
			fixed = false;
			id = idCount++;
		}
		
		public final function distance(p:Particle):Number
		{
			
			return Math.sqrt( squareDistance( p ) );
			
		}
		
		public final function squareDistance(p:Particle):Number
		{
			var dx:Number, dy:Number, dz:Number;
			dx = position.x - p.position.x;
			dy = position.y - p.position.y;
			dz = position.z - p.position.z;
			return (dx * dx + dy * dy + dz * dz);
		}
		
		protected function reset():void {
			age = 0;
			dead = false;
			position.x = position.y = position.z = 0;
			clearVelocity();
			clearForce();
			mass = 1;
		}
		public function clearVelocity():void
		{
			velocity.x = velocity.y = velocity.z = 0;
		}

		public function clearForce():void
		{
			force.x = force.y = force.z = 0;
		}
		
		public function get mass():Number { return _mass; }
		
		public function set mass(value:Number):void 
		{
			_mass = value;
		}
		
		public function get force():Vector3D { return _force; }
		
		public function set force(value:Vector3D):void 
		{
			_force = value;
		}
		
		public function get position():Vector3D { return _position; }
		
		public function set position(value:Vector3D):void 
		{
			_position = value;
		}
		
		public function get velocity():Vector3D { return _velocity; }
		
		public function set velocity(value:Vector3D):void 
		{
			_velocity = value;
		}
		
		public function get age():Number { return _age; }
		
		public function set age(value:Number):void 
		{
			_age = value;
		}
		
		public function get dead():Boolean { return _dead; }
		
		public function set dead(value:Boolean):void 
		{
			_dead = value;
		}
		
		public function get fixed():Boolean { return _fixed; }
		
		public function set fixed(value:Boolean):void 
		{
			_fixed = value;
			if( value ) velocity.x = velocity.y = velocity.z = 0;
		}
		
		public function get color():uint { return _color; }
		
		public function set color(value:uint):void 
		{
			_color = value;
		}
		
		public function get id():int { return _id; }
		
		public function set id(value:int):void 
		{
			//_id = value;
		}
		
		public final function draw( g:Graphics, size:Number = 2 ):void
		{
			//g.lineStyle( 0, color );
			g.drawCircle( position.x, position.y, size );
		}
	}

}